cmake_minimum_required(VERSION 3.16)

project(testcode)

set(CMAKE_CXX_FLAGS "-std=c++17")

set(CMAKE_BUILD_TYPE Debug)

# OpenCV 4
find_package(OpenCV 4 REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})

# Boost
find_package(Boost REQUIRED)
find_package(Boost COMPONENTS filesystem thread REQUIRED)
include_directories(${Boost_INCLUDE_DIRS})

# glog
find_package(glog 0.6.0 REQUIRED)
include_directories(${GLOG_INCLUDE_DIR})

# pangolin
find_package(Pangolin REQUIRED)
include_directories(${Pangolin_INCLUDE_DIRS})

# Sophus
find_package(Sophus REQUIRED)
include_directories(${Sophus_INCLUDE_DIRS})

# fmt
find_package(fmt REQUIRED)

# g2o
find_package(g2o REQUIRED)
include_directories(${G2O_INCLUDE_DIRS})

# gtsam
find_package(GTSAM REQUIRED)
include_directories(${GTSAM_INCLUDE_DIR})

# Eigen
include_directories("/usr/include/eigen3")

# PCL
find_package(PCL 1.10 REQUIRED)
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})

# fast feature extract
find_package(fast REQUIRED)
include_directories(${fast_INCLUDE_DIRS})

include_directories(
  ${PROJECT_SOURCE_DIR}
  ${PROJECT_SOURCE_DIR}/ulog_parser
)

set(THIRD_PARTY_LIBS
  ${OpenCV_LIBS}
  ${fast_LIBRARIES}
  ${Sophus_LIBRARIES}
  ${Pangolin_LIBRARIES}
  glog::glog
  g2o_core g2o_stuff
  gtsam
  gtsam_unstable
  fmt::fmt
)

# ulog parser library
add_library(ulog_parser
  ulog_parser/ulog_parser.cc
  ulog_parser/ulog_parser.h
  ulog_parser/ulog_messages.h
)
target_link_libraries(ulog_parser ${THIRD_PARTY_LIBS})

# ref: https://stackoverflow.com/questions/14306642/adding-multiple-executables-in-cmake
file(GLOB APP_SOURCE_FILES RELATIVE ${PROJECT_SOURCE_DIR} *.cc)
foreach(test_file ${APP_SOURCE_FILES})
  string(REPLACE ".cc" "" testname ${test_file})
  message(STATUS "exec: ${testname}")
  add_executable(${testname} ${test_file})
  target_link_libraries(${testname} ${THIRD_PARTY_LIBS} ulog_parser)
endforeach(test_file ${APP_SOURCE_FILES})
